package base.shiro.demo.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@ApiModel(description = "返回对象")
@Data
public class Res<T> implements Serializable {

	private final static int ERROR_CODE = 500;

	@ApiModelProperty(value = "返回代码", name = "code", example = "200", required = true)
	private int code;

	@ApiModelProperty(value = "返回消息", name = "msg", example = "success")
	private String msg;

	@ApiModelProperty(value = "返回数据", name = "data", example = "{name:'jiang'}")
	private T data;

	public Res() {
		this.msg = "success";
	}

	public Res(T value) {
		this.msg = "success";
		this.data = value;
	}

	public Res<T> error(int code, String msg) {
		this.code = code;
		this.msg = msg;
		return this;
	}

	public Res<T> error(String msg) {
		this.code = ERROR_CODE;
		this.msg = msg;
		return this;
	}

	public Res<T> error(String msg, T data) {
		this.code = ERROR_CODE;
		this.msg = msg;
		this.data = data;
		return this;
	}
}
